home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Gamer (Italian) 35
/
PC Gamer IT CD 35 1-2.iso
/
Elink
/
NSCOMM
/
NCJS10.JAR
/
additem.js
next >
Wrap
Text File
|
1997-10-20
|
10KB
|
399 lines
/*
* Additem.js
*
* Copyright (c) 1997 Netscape Communications Corporation, All Rights Reserved
*
*/
var selector = null;
var container;
var containerObject = null;
var gProps = null;
function handleLoad() {
gProps = null;
opener.PropertiesCallback(this);
// after we've filled the item, for additions, make sure that we
// are allowed to add before going further.
containerObject = selector.parent.titlebar.document.demo.findContainerByName(container);
if ((gProps == null) && (containerObject != null)) {
if (!containerObject.getCanAddItems()) {
alert(window.depth.getLocalString("addBlocked"));
self.close();
}
}
// on enter for the dialog, set the focus to the dialog
window.focus();
window.document.layers['general'].document.scheduler.name.focus();
// For Castanet channels, disable the cache tab
if (gProps != null) {
var propType = gProps.getType();
if (propType == 2) {
window.document.layers['cacheTab'].visibility="hide";
}
}
}
function ValidateGeneral(prefsWindow)
{
var generalLayer = prefsWindow.document.layers['general'];
var form = generalLayer.document.scheduler;
if (fieldEmpty(form.elements['name'])) {
alert(window.depth.getLocalString("You must specify a name for this channel"));
form.elements['name'].focus();
form.elements['name'].select();
return false;
}
if (fieldEmpty(form.url)) {
alert(window.depth.getLocalString("You must specify a location for this channel"));
form.url.focus();
form.url.select();
return false;
} else {
var newURL = null;
newURL = selector.parent.titlebar.document.demo.getValidURL(form.url.value);
if (newURL == null) {
form.url.focus();
form.url.select();
alert(window.depth.getLocalString("invalidURL"));
return false;
} else {
form.url.value = newURL;
}
}
return true;
}
function UpdateTimeFields(prefsWindow)
{
var generalLayer = prefsWindow.document.layers['general'];
var form = generalLayer.document.scheduler;
var newInterval = form.freq.options[form.freq.selectedIndex].value;
var specialLayer;
if (newInterval == "-5") {
generalLayer.document.layers['weekLayer'].visibility="hide";
specialLayer = generalLayer.document.layers['dayLayer'];
specialLayer.visibility="show";
} else if (newInterval == "-6") {
generalLayer.document.layers['dayLayer'].visibility="hide";
specialLayer = generalLayer.document.layers['weekLayer'];
specialLayer.visibility="show";
} else {
generalLayer.document.layers['weekLayer'].visibility="hide";
generalLayer.document.layers['dayLayer'].visibility="hide";
}
return;
}
function FormValues(prefsWindow) {
var scheduler = prefsWindow.document.layers['general'].document.scheduler;
var cache = prefsWindow.document.layers['cache'].document.cache;
var display = prefsWindow.document.layers['display'].document.winType;
var day = prefsWindow.document.layers['general'].layers['dayLayer'].document.times;
var week = prefsWindow.document.layers['general'].layers['weekLayer'].document.times;
this.index = scheduler.index.value;
this.name = scheduler.name.value;
this.url = scheduler.url.value;
if ((this.url != null) &&
((this.url.indexOf("castanet") != -1) || (this.url.indexOf("?start")==(this.url.length-6))) ) {
this.type = 2;
} else {
this.type = scheduler.type.value;
}
this.active = scheduler.active.checked;
this.freq = scheduler.freq.options[scheduler.freq.selectedIndex].value;
if (this.freq == "-5" ) {
this.time = day.time.value;
this.ampm = day.ampm.options[day.ampm.selectedIndex].value;
}
else if (this.freq == "-6" ) {
this.time = week.time.value;
this.ampm = week.ampm.options[week.ampm.selectedIndex].value;;
this.day = week.day.options[week.day.selectedIndex].value;
}
this.depth = cache.depth.value;
this.size = cache.size.value;
this.inSiteOnly = (cache.external.value == "0")
this.mode = prefsWindow.document.layers['display'].mode;
}
function handleOK() {
var props = gProps;
var updateTimer = false;
if ( !ValidateGeneral(window) ) return;
var form = new FormValues(window);
if (form.index == "-1") {
var oldData = selector.parent.titlebar.document.demo.findItemByName(form.name);
if (oldData != null) {
if (!confirm(window.depth.getLocalString("A channel with the name ") + form.name + window.depth.getLocalString(" already exists.")))
return;
}
var newName = selector.parent.titlebar.document.demo.getEncodedName(form.name, container);
if (newName == null || newName == "") {
alert("An error occurred while saving the item");
}
var prefName = "netcaster.channel." + newName;
props = selector.parent.titlebar.document.demo.newDataItem(form.url);
props.setPrefsKey(prefName);
} else {
props.setURL(form.url);
}
props.setItemName(form.name);
if (props.getType() != 2)
{
props.setDepth(java.lang.Integer.parseInt(form.depth));
var tmp = (parseInt(form.size) * 1024);
props.setMaxSize(java.lang.Integer.parseInt(tmp));
if (form.inSiteOnly) {
props.setCrawlInSite(java.lang.Boolean.TRUE);
}
else {
props.setCrawlInSite(java.lang.Boolean.FALSE);
}
}
var newFreq = java.lang.Integer.parseInt(form.freq);
if (form.index != "-1") {
updateTimer = (props.getFrequency() != newFreq);
}
props.setFrequency(newFreq);
var time = parseTimeForBackend(form);
if (time == -10) {
alert("Please enter a valid time for the update to occur.");
return;
}
if (form.index != "-1") {
updateTimer |= (props.getUpdateTime() != time);
}
props.setUpdateTime(java.lang.Integer.parseInt(time));
if (form.active) {
props.setScheduled(java.lang.Boolean.TRUE);
}
else {
props.setScheduled(java.lang.Boolean.FALSE);
}
props.setType(java.lang.Integer.parseInt(form.type));
props.setMode(form.mode);
if (form.index == "-1") {
selector.parent.titlebar.document.demo.addItem(props, container);
}
else {
props.changed();
if (updateTimer == 1) {
props.updateProps();
}
}
if (opener.EditCallback && opener.EditCallback != null) {
if (form.index == -1) {
opener.EditCallback(true);
} else {
opener.EditCallback(false);
}
}
self.close();
}
function editItem(props) {
var scheduler = document.layers['general'].document.scheduler;
var cache = document.layers['cache'].document.cache;
scheduler.index.value = 0;
gProps = props;
scheduler.name.value = props.getItemName();
scheduler.url.value = props.getURL();
scheduler.type.value = props.getType();
scheduler.freq.value = props.getFrequency();
scheduler.interval.value = props.getFrequency();
scheduler.active.checked = (props.getScheduled());
parseTimeForFrontend(document.layers['general'], scheduler, props.getUpdateTime());
if (props.getType() == 2)
{
cache.depth.value = 0;
cache.size.value = "" + (parseInt(props.getMaxSize()));
}
else {
cache.depth.value = props.getDepth();
cache.size.value = "" + (parseInt(props.getMaxSize()) / 1024);
if (props.crawlInSite()) {
cache.external.value = "0";
} else {
cache.external.value = "1";
}
}
var mode = props.getMode();
mode = mode + "";
switch (mode) {
case "webtop":
document.layers['display'].document.forms["winType"].mode[1].checked = true;
break;
case "full":
document.layers['display'].document.forms["winType"].mode[0].checked = true;
break;
case "window":
document.layers['display'].document.forms["winType"].mode[0].checked = true;
}
document.layers['display'].ChangeThumbnail();
}
function parseTimeForFrontend(first, form, time) {
var tmp = 0;
var applet = selector.parent.titlebar.document.demo;
for (tmp = 0; tmp < form.freq.length; tmp++) {
if (form.interval.value == form.freq[tmp].value)
form.freq.selectedIndex = tmp;
}
if ( form.interval.value == '-6' ) {
var week = first.layers['weekLayer'].document.times;
if (time < 1440)
tmp = 0;
else
tmp = time / 1440;
week.day.selectedIndex = parseInt(tmp);
time = time - ( (parseInt(tmp) * 1440) );
}
if ( parseInt(form.interval.value) <= -5 ) {
var week = first.layers['weekLayer'].document.times;
var day = first.layers['dayLayer'].document.times;
if (time < 720)
tmp = 0;
else
tmp = 1;
if ( parseInt(form.interval.value) == -6 )
week.ampm.selectedIndex = parseInt(tmp);
else
day.ampm.selectedIndex = parseInt(tmp);
time -= parseInt( (parseInt(tmp) * 720) );
// Find the hour
tmp = time / 60;
if (isNaN(parseInt(tmp))) {
tmp = 0;
}
time -= (parseInt(tmp) * 60);
if ( parseInt(time) < 10 )
time = "0" + parseInt(time);
else
time = parseInt(time);
if (parseInt(tmp) == 0) {
tmp = 12;
}
if ( parseInt(form.interval.value) == -6 ) {
week.time.value = parseInt(tmp) + ":" + time;
}
else {
day.time.value = parseInt(tmp) + ":" + time;
}
UpdateTimeFields(window);
}
}
function parseTimeForBackend(form) {
var ret = -1;
var applet = selector.parent.titlebar.document.demo;
if ( parseInt(form.freq) <= -5 ) {
var hour, minute;
if (!applet.validateTimeString(form.time))
return -10;
hour = applet.getHour(form.time);
minute = applet.getMinute(form.time);
var hourInt = parseInt(hour);
if (hourInt == 12) {
hourInt = 0;
}
hourInt = hourInt * 60;
var minInt = parseInt(minute);
if ((hourInt < 0) && (minInt <= 0))
return -10;
ret = hourInt + minInt + parseInt(form.ampm);
if (ret > 1440)
return -10;
}
if ( form.freq == '-6' ) {
ret += parseInt(form.day);
}
return ret;
}
function clearCache() {
var props = gProps;
props.clearCache();
}
function cancelUpdate() {
var props = gProps;
props.cancelUpdate();
}
void(0);